package com.migu.contacts.main;

import android.view.View;

import com.frank.libandroid.BaseActivity;
import com.frank.libandroid.DataStore;
import com.frank.libandroid.Key;
import com.migu.contacts.bean.GiftBean;
import com.migu.contacts.bean.GiftTip;
import com.migu.contacts.databinding.ActivityGiftBinding;
import com.migu.contacts.util.PopUtil;
import com.migu.contacts.widget.Callback;
import com.migu.contacts.widget.Label2;

public class GiftActivity extends BaseActivity<ActivityGiftBinding> {
    GiftTip mGiftTip;

    @Override
    protected void initData() {
        super.initData();
        mGiftTip = DataStore.get(KEY);
        if (mGiftTip == null) {
            mGiftTip = new GiftTip();
        }
        Label2.LabelBean labelBean = new Label2.LabelBean("提醒日期", mGiftTip.tipTime, 0, true);
        mBinding.dateTip.setBean(labelBean);
        mBinding.dateTip.mBinding.ivArrow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PopUtil.showDatePicker(mActivity, mGiftTip.tipTime, new Callback<String>() {
                    @Override
                    public void onComplete(String s) {
                        mGiftTip.tipTime = s;
                        labelBean.right = s;
                        labelBean.notifyChange();
                    }
                });
            }
        });
        mBinding.setBean(mGiftTip);
    }

    public void save(View view) {
        DataStore.put(KEY, mGiftTip);
        setResult(RESULT_OK);
        finish();
    }

    public static final Key<GiftTip> KEY = new Key<GiftTip>();

    public void goGift(View view) {
        startActivityForResult(GiftSelectActivity.class, new Runnable() {
            @Override
            public void run() {
                GiftBean giftBean = DataStore.get(GiftSelectActivity.KEY);
                if (giftBean == null) {
                    return;
                }
                GiftTip birthdayTip = mBinding.getBean();
                birthdayTip.content = giftBean.name;
            }
        });
    }
}